<?php


namespace app\home\model\page\circle;


use app\api\model\dao\Circle;
use app\library\Error;
use app\library\PageBase;

class AddLabel extends PageBase
{
    public function __construct()
    {
        parent::__construct();
    }

    public function excute($param)
    {
        $ret = $this->checkParam($param);
        if ($ret) {
            return $this->getRes(Error::ERR_PARAM, $ret);
        }
        $objCircle = new Circle();
        $input['id'] = $param['cir_id'];
        $input['label'] = $param['label'];
        try {
            $ret = $objCircle->updateCircle($input);
        } catch (\Exception $e) {
            return $this->getRes(Error::ERR_SYS, $e->getMessage());
        }
        return $this->getRes();
    }

    public function checkParam($param)
    {
        $rule = [
            'cir_id' => 'require',
            'label' => 'require',
        ];
        $msg = [
            'cir_id.require' => '圈子ID必须',
            'label.require' => '圈子标签必须',
        ];

        $validate = new \think\Validate($rule, $msg);
        $result = $validate->check($param);
        if (!$result) {
            return $validate->getError();
        }
        return '';
    }
}